package o;

import java.io.Closeable;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

final class fwn implements Closeable {
    private static final Logger ˎ = Logger.getLogger(fwi.class.getName());
    private int ʼ = 16384;
    private final boolean ˊ;
    final b ˋ = new b(this.ˏ);
    private final fxi ˏ = new fxi();
    private final fxj ॱ;
    private boolean ॱॱ;

    fwn(fxj o_fxj, boolean z) {
        this.ॱ = o_fxj;
        this.ˊ = z;
    }

    public synchronized void ˊ() throws IOException {
        if (this.ॱॱ) {
            throw new IOException("closed");
        } else if (this.ˊ) {
            if (ˎ.isLoggable(Level.FINE)) {
                ˎ.fine(fvg.ˊ(">> CONNECTION %s", fwi.ˊ.ᐝ()));
            }
            this.ॱ.ˊ(fwi.ˊ.ॱॱ());
            this.ॱ.flush();
        }
    }

    public synchronized void ˏ(fwl o_fwl) throws IOException {
        if (this.ॱॱ) {
            throw new IOException("closed");
        }
        this.ʼ = o_fwl.ˋ(this.ʼ);
        if (o_fwl.ˏ() != -1) {
            this.ˋ.ˊ(o_fwl.ˏ());
        }
        ˏ(0, 0, (byte) 4, (byte) 1);
        this.ॱ.flush();
    }

    public synchronized void ˊ(int i, int i2, List<fwb> list) throws IOException {
        if (this.ॱॱ) {
            throw new IOException("closed");
        }
        this.ˋ.ॱ(list);
        long ॱ = this.ˏ.ॱ();
        int min = (int) Math.min((long) (this.ʼ - 4), ॱ);
        ˏ(i, min + 4, (byte) 5, ॱ == ((long) min) ? (byte) 4 : (byte) 0);
        this.ॱ.ʼ(ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED & i2);
        this.ॱ.ˎ(this.ˏ, (long) min);
        if (ॱ > ((long) min)) {
            ˋ(i, ॱ - ((long) min));
        }
    }

    public synchronized void ˎ() throws IOException {
        if (this.ॱॱ) {
            throw new IOException("closed");
        }
        this.ॱ.flush();
    }

    public synchronized void ˊ(boolean z, int i, int i2, List<fwb> list) throws IOException {
        if (this.ॱॱ) {
            throw new IOException("closed");
        }
        ॱ(z, i, list);
    }

    public synchronized void ॱ(int i, fwf o_fwf) throws IOException {
        if (this.ॱॱ) {
            throw new IOException("closed");
        } else if (o_fwf.ˏॱ == -1) {
            throw new IllegalArgumentException();
        } else {
            ˏ(i, 4, (byte) 3, (byte) 0);
            this.ॱ.ʼ(o_fwf.ˏॱ);
            this.ॱ.flush();
        }
    }

    public synchronized int ˏ() {
        return this.ʼ;
    }

    public synchronized void ॱ(boolean z, int i, fxi o_fxi, int i2) throws IOException {
        if (this.ॱॱ) {
            throw new IOException("closed");
        }
        byte b = (byte) 0;
        if (z) {
            b = (byte) 1;
        }
        ˋ(i, b, o_fxi, i2);
    }

    void ˋ(int i, byte b, fxi o_fxi, int i2) throws IOException {
        ˏ(i, i2, (byte) 0, b);
        if (i2 > 0) {
            this.ॱ.ˎ(o_fxi, (long) i2);
        }
    }

    public synchronized void ˊ(fwl o_fwl) throws IOException {
        synchronized (this) {
            if (this.ॱॱ) {
                throw new IOException("closed");
            }
            ˏ(0, o_fwl.ˎ() * 6, (byte) 4, (byte) 0);
            for (int i = 0; i < 10; i++) {
                if (o_fwl.ˊ(i)) {
                    int i2;
                    if (i == 4) {
                        i2 = 3;
                    } else if (i == 7) {
                        i2 = 4;
                    } else {
                        i2 = i;
                    }
                    this.ॱ.ʻ(i2);
                    this.ॱ.ʼ(o_fwl.ˏ(i));
                }
            }
            this.ॱ.flush();
        }
    }

    public synchronized void ˋ(boolean z, int i, int i2) throws IOException {
        byte b = (byte) 0;
        synchronized (this) {
            if (this.ॱॱ) {
                throw new IOException("closed");
            }
            if (z) {
                b = (byte) 1;
            }
            ˏ(0, 8, (byte) 6, b);
            this.ॱ.ʼ(i);
            this.ॱ.ʼ(i2);
            this.ॱ.flush();
        }
    }

    public synchronized void ˊ(int i, fwf o_fwf, byte[] bArr) throws IOException {
        if (this.ॱॱ) {
            throw new IOException("closed");
        } else if (o_fwf.ˏॱ == -1) {
            throw fwi.ॱ("errorCode.httpCode == -1", new Object[0]);
        } else {
            ˏ(0, bArr.length + 8, (byte) 7, (byte) 0);
            this.ॱ.ʼ(i);
            this.ॱ.ʼ(o_fwf.ˏॱ);
            if (bArr.length > 0) {
                this.ॱ.ˊ(bArr);
            }
            this.ॱ.flush();
        }
    }

    public synchronized void ॱ(int i, long j) throws IOException {
        if (this.ॱॱ) {
            throw new IOException("closed");
        } else if (j == 0 || j > 2147483647L) {
            throw fwi.ॱ("windowSizeIncrement == 0 || windowSizeIncrement > 0x7fffffffL: %s", Long.valueOf(j));
        } else {
            ˏ(i, 4, (byte) 8, (byte) 0);
            this.ॱ.ʼ((int) j);
            this.ॱ.flush();
        }
    }

    public void ˏ(int i, int i2, byte b, byte b2) throws IOException {
        if (ˎ.isLoggable(Level.FINE)) {
            ˎ.fine(fwi.ॱ(false, i, i2, b, b2));
        }
        if (i2 > this.ʼ) {
            throw fwi.ॱ("FRAME_SIZE_ERROR length > %d: %d", Integer.valueOf(this.ʼ), Integer.valueOf(i2));
        } else if ((Integer.MIN_VALUE & i) != 0) {
            throw fwi.ॱ("reserved bit set: %s", Integer.valueOf(i));
        } else {
            ˏ(this.ॱ, i2);
            this.ॱ.ॱॱ(b & 255);
            this.ॱ.ॱॱ(b2 & 255);
            this.ॱ.ʼ(ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED & i);
        }
    }

    public synchronized void close() throws IOException {
        this.ॱॱ = true;
        this.ॱ.close();
    }

    private static void ˏ(fxj o_fxj, int i) throws IOException {
        o_fxj.ॱॱ((i >>> 16) & 255);
        o_fxj.ॱॱ((i >>> 8) & 255);
        o_fxj.ॱॱ(i & 255);
    }

    private void ˋ(int i, long j) throws IOException {
        while (j > 0) {
            int min = (int) Math.min((long) this.ʼ, j);
            j -= (long) min;
            ˏ(i, min, (byte) 9, j == 0 ? (byte) 4 : (byte) 0);
            this.ॱ.ˎ(this.ˏ, (long) min);
        }
    }

    void ॱ(boolean z, int i, List<fwb> list) throws IOException {
        if (this.ॱॱ) {
            throw new IOException("closed");
        }
        this.ˋ.ॱ(list);
        long ॱ = this.ˏ.ॱ();
        int min = (int) Math.min((long) this.ʼ, ॱ);
        byte b = ॱ == ((long) min) ? (byte) 4 : (byte) 0;
        if (z) {
            b = (byte) (b | 1);
        }
        ˏ(i, min, (byte) 1, b);
        this.ॱ.ˎ(this.ˏ, (long) min);
        if (ॱ > ((long) min)) {
            ˋ(i, ॱ - ((long) min));
        }
    }
}
